# Copyright 2018- The Pixie Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0

load("//bazel:pl_build_system.bzl", "pl_cc_binary", "pl_cc_library", "pl_cc_test", "pl_cc_test_library")

package(default_visibility = ["//src/carnot:__subpackages__"])

pl_cc_library(
    name = "cc_library",
    srcs = glob(
        [
            "*.cc",
            "*.h",
        ],
        exclude = [
            "**/*_test.cc",
            "**/*_benchmark.cc",
            "**/*_mock.h",
            "**/*test_utils.h",
        ],
    ),
    hdrs = [
        "exec_node.h",
        "exec_state.h",
    ],
    deps = [
        "//src/carnot/carnotpb:carnot_pl_cc_proto",
        "//src/carnot/exec/ml:cc_library",
        "//src/carnot/plan:cc_library",
        "//src/carnot/planpb:plan_pl_cc_proto",
        "//src/carnot/udf:cc_library",
        "//src/common/uuid:cc_library",
        "//src/shared/types:cc_library",
        "//src/table_store/table:cc_library",
        "@com_github_apache_arrow//:arrow",
        "@com_github_grpc_grpc//:grpc++",
        "@com_github_opentelemetry_proto//:logs_service_grpc_cc",
        "@com_github_opentelemetry_proto//:metrics_service_grpc_cc",
        "@com_github_opentelemetry_proto//:trace_service_grpc_cc",
        "@com_github_rlyeh_sole//:sole",
        "@com_github_simdutf_simdutf//:libsimdutf",
        "@com_google_absl//absl/container:node_hash_map",
    ],
)

pl_cc_test_library(
    name = "test_utils",
    hdrs = glob(["*test_utils.h"]),
    deps = [
        ":exec_node_test_helpers",
        "@com_github_apache_arrow//:arrow",
    ],
)

pl_cc_test(
    name = "expression_evaluator_test",
    srcs = ["expression_evaluator_test.cc"],
    deps = [
        ":cc_library",
        ":test_utils",
        "//src/carnot/planpb:plan_testutils",
        "@com_github_apache_arrow//:arrow",
    ],
)

pl_cc_binary(
    name = "expression_evaluator_benchmark",
    testonly = 1,
    srcs = ["expression_evaluator_benchmark.cc"],
    deps = [
        ":cc_library",
        ":test_utils",
        "//src/carnot/planpb:plan_testutils",
        "//src/common/benchmark:cc_library",
        "//src/datagen:datagen_library",
        "@com_github_apache_arrow//:arrow",
        "@com_google_benchmark//:benchmark_main",
    ],
)

pl_cc_test_library(
    name = "exec_node_test_helpers",
    hdrs = glob(["*_mock.h"]),
    deps = [
        ":cc_library",
    ],
)

pl_cc_test(
    name = "map_node_test",
    srcs = ["map_node_test.cc"] + glob(["*_mock.h"]),
    deps = [
        ":cc_library",
        ":exec_node_test_helpers",
        ":test_utils",
        "//src/carnot/planpb:plan_testutils",
        "@com_github_apache_arrow//:arrow",
    ],
)

pl_cc_test(
    name = "limit_node_test",
    srcs = ["limit_node_test.cc"] + glob(["*_mock.h"]),
    deps = [
        ":cc_library",
        ":exec_node_test_helpers",
        ":test_utils",
        "//src/carnot/planpb:plan_testutils",
        "@com_github_apache_arrow//:arrow",
    ],
)

pl_cc_test(
    name = "filter_node_test",
    srcs = ["filter_node_test.cc"] + glob(["*_mock.h"]),
    deps = [
        ":cc_library",
        ":exec_node_test_helpers",
        ":test_utils",
        "//src/carnot/planpb:plan_testutils",
        "@com_github_apache_arrow//:arrow",
    ],
)

pl_cc_test(
    name = "agg_node_test",
    srcs = ["agg_node_test.cc"] + glob(["*_mock.h"]),
    deps = [
        ":cc_library",
        ":exec_node_test_helpers",
        ":test_utils",
        "//src/carnot/planpb:plan_testutils",
        "@com_github_apache_arrow//:arrow",
    ],
)

pl_cc_test(
    name = "union_node_test",
    srcs = ["union_node_test.cc"] + glob(["*_mock.h"]),
    deps = [
        ":cc_library",
        ":exec_node_test_helpers",
        ":test_utils",
        "//src/carnot/planpb:plan_testutils",
        "@com_github_apache_arrow//:arrow",
    ],
)

pl_cc_test(
    name = "equijoin_node_test",
    srcs = ["equijoin_node_test.cc"] + glob(["*_mock.h"]),
    deps = [
        ":cc_library",
        ":exec_node_test_helpers",
        ":test_utils",
        "//src/carnot/planpb:plan_testutils",
        "@com_github_apache_arrow//:arrow",
    ],
)

pl_cc_test(
    name = "memory_source_node_test",
    srcs = ["memory_source_node_test.cc"] + glob(["*_mock.h"]),
    deps = [
        ":cc_library",
        ":exec_node_test_helpers",
        ":test_utils",
        "//src/carnot/planpb:plan_testutils",
        "@com_github_apache_arrow//:arrow",
    ],
)

pl_cc_test(
    name = "memory_sink_node_test",
    srcs = ["memory_sink_node_test.cc"] + glob(["*_mock.h"]),
    deps = [
        ":cc_library",
        ":exec_node_test_helpers",
        ":test_utils",
        "//src/carnot/planpb:plan_testutils",
        "@com_github_apache_arrow//:arrow",
    ],
)

pl_cc_test(
    name = "grpc_source_node_test",
    srcs = ["grpc_source_node_test.cc"] + glob(["*_mock.h"]),
    deps = [
        ":cc_library",
        ":exec_node_test_helpers",
        ":test_utils",
        "//src/carnot/planpb:plan_testutils",
        "@com_github_apache_arrow//:arrow",
    ],
)

pl_cc_test(
    name = "grpc_sink_node_test",
    srcs = ["grpc_sink_node_test.cc"] + glob(["*_mock.h"]),
    deps = [
        ":cc_library",
        ":exec_node_test_helpers",
        ":test_utils",
        "//src/carnot/planpb:plan_testutils",
        "@com_github_apache_arrow//:arrow",
        "@com_github_grpc_grpc//:grpc++_test",
    ],
)

pl_cc_test(
    name = "exec_graph_test",
    srcs = ["exec_graph_test.cc"],
    deps = [
        ":cc_library",
        ":test_utils",
        "//src/carnot/planpb:plan_testutils",
        "@com_github_apache_arrow//:arrow",
    ],
)

pl_cc_test(
    name = "row_tuple_test",
    timeout = "long",
    srcs = ["row_tuple_test.cc"],
    tags = ["cpu:4"],
    deps = [
        ":cc_library",
    ],
)

pl_cc_test(
    name = "udtf_source_node_test",
    srcs = ["udtf_source_node_test.cc"],
    deps = [
        ":cc_library",
        ":test_utils",
        "//src/carnot/planpb:plan_testutils",
        "@com_github_apache_arrow//:arrow",
    ],
)

pl_cc_test(
    name = "grpc_router_test",
    srcs = ["grpc_router_test.cc"],
    deps = [
        ":cc_library",
        ":test_utils",
        "//src/carnot/planpb:plan_testutils",
        "@com_github_grpc_grpc//test/core/util:grpc_test_util_base",
    ],
)

pl_cc_test(
    name = "empty_source_node_test",
    srcs = ["empty_source_node_test.cc"],
    deps = [
        ":cc_library",
        ":exec_node_test_helpers",
        ":test_utils",
        "//src/carnot/planpb:plan_testutils",
        "@com_github_apache_arrow//:arrow",
    ],
)

pl_cc_binary(
    name = "grpc_sink_node_benchmark",
    testonly = 1,
    srcs = ["grpc_sink_node_benchmark.cc"],
    deps = [
        ":cc_library",
        ":test_utils",
        "//src/carnot/planpb:plan_testutils",
        "//src/common/benchmark:cc_library",
        "@com_github_grpc_grpc//:grpc++_test",
    ],
)

pl_cc_test(
    name = "otel_export_sink_node_test",
    srcs = ["otel_export_sink_node_test.cc"] + glob(["*_mock.h"]),
    deps = [
        ":cc_library",
        ":exec_node_test_helpers",
        ":test_utils",
        "//src/carnot/planpb:plan_testutils",
        "@com_github_apache_arrow//:arrow",
        "@com_github_grpc_grpc//:grpc++_test",
    ],
)
